package LeetCode;

public class LC_066_PlusOne {
    public static void main(String[] args) {

    }

    static class Solution {
        public int[] plusOne(int[] digits) {
            int length = digits.length;
            int[] res;
            if (length <= 0)
                return digits;

            int carry = 1;
            for (int i = length - 1; i >= 0; i--) {
                int val = digits[i] + carry;
                carry = val / 10;
                digits[i] = val % 10;

                if (carry == 0)
                    return digits;
            }

            if (carry > 0) {
                res = new int[length + 1];
                res[0] = carry;
                return res;
            } else
                return digits;
        }
    }
}
